package com.aaa.user.dao;

import com.aaa.entity.UmsMemberReceiveAddress;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * fileName:UserDao
 * description:
 * author:lk
 * createTime:2020/1/9 19:35
 * version:1.0.0
 */
public interface UserDao {
    /**
     * 根据id获取用户中心的用户信息
     * @param id
     * @return 4vbnm,bn
     */
    @Select("select id,nickname,icon,birthday,history_integration,growth,integration,balance from ums_member where id = #{id}")
    List<Map>  getUserById(Long id);

    /**
     * 根据用户id查询用户收货地址列表
     */
    @Select("select id,member_id,name,phone_number,default_status,post_code,province,city,region,detail_address from ums_member_receive_address where member_id=#{memberId}")
    List<Map> listAddressByMemberId(long memberId);

    /**
     * 根据id查询收获地址
     * @param id
     * @return
     */
    @Select("select id,member_id,name,phone_number,default_status,post_code,province,city,region,detail_address from ums_member_receive_address where id=#{id}")
    Map getAddressById(Long id);

    /**
     * 查询默认收货地址
     */
    @Select("select id,member_id,name,phone_number,default_status,post_code,province,city,region,detail_address from ums_member_receive_address where member_id=#{memberId} and default_status=0 ")
    Map getDetailAddress(long memberId);

    /**
     * 添加收货地址
     */
    @Insert("insert into ums_member_receive_address (member_id,name,phone_number,default_status,post_code,province,city,region,detail_address) values(#{memberId},#{name},#{phoneNumber},#{defaultStatus},#{postCode},#{province},#{city},#{region},#{detailAddress})")
    int addAddress(UmsMemberReceiveAddress address);


    /**
     * 根据id删除收货地址
     */
    @Delete("delete from ums_member_receive_address where id = #{id} ")
    int deleteAddressById(long id);

    /**
     * 修改收货地址
     */
    @Update("update ums_member_receive_address  set member_id=#{member_id},name=#{name},phone_number=#{phone_number},default_status=#{default_status},post_code=#{post_code},province=#{province},city=#{city},region=#{region},detail_address=#{detail_address} where id = #{id} ")
    int updateAddress(Map map);

    /**
     * 查询用户消费记录
     * @param memberId
     * @return
     */
    @Select("select id,member_id,money,DATE_FORMAT(eh.time,'%Y-%m-%d %H:%i:%S') as time,type from ums_member_expenditure_history eh where member_id = #{memberId}")
    List<Map> payHistory(Long memberId);

}
